package com.zs.propertymanage.controller;

import com.zs.propertymanage.annotation.SystemLog;
import com.zs.propertymanage.dataObj.R;
import com.zs.propertymanage.dataObj.entity.House;
import com.zs.propertymanage.service.impl.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 房屋管理
 */
@RestController
@RequestMapping("/house")
@CrossOrigin
public class HouseController {

    @Autowired
    private HouseService houseService;

    // 按条件分页查询房屋信息
    @GetMapping("")
    @ResponseBody
    public R getHouse(String search, Integer currentPage, Integer pageSize, Integer orgId) {
        return houseService.getHouse(search, currentPage, pageSize, orgId);
    }

    /**
     * 添加房屋
     *
     * @param house 房屋实体
     * @return R
     */
    @PostMapping("")
    @ResponseBody
    @SystemLog(name = "添加房屋")
    public R addHouse(@RequestBody House house) {
        return houseService.addHouse(house);
    }

    /**
     * 更新房屋
     *
     * @param house 房屋实体
     * @return R
     */
    @PutMapping("")
    @ResponseBody
    @SystemLog(name = "更新房屋")
    public R updateHouse(@RequestBody House house) {
        return houseService.updateHouse(house);
    }

    /**
     * 删除房屋
     *
     * @param houseId 房屋id
     * @return R
     */
    @DeleteMapping("/{houseId}")
    @ResponseBody
    @SystemLog(name = "删除房屋")
    public R deleteHouse(@PathVariable Integer houseId) {
        return houseService.deleteHouse(houseId);
    }

    /**
     * 获取所有房屋状态
     *
     * @return R
     */
    @GetMapping("/status")
    @ResponseBody
    public R getAllHouseStatus() {
        return houseService.getAllHouseStatus();
    }

    /**
     * 获取所有房屋类型
     *
     * @return R
     */
    @GetMapping("/type")
    @ResponseBody
    public R getAllHouseType() {
        return houseService.getAllHouseType();
    }

    // 添加房屋类型
    @PostMapping("/type")
    @ResponseBody
    @SystemLog(name = "添加房屋类型")
    public R addHouseType(String typeName) {
        return houseService.addHouseType(typeName);
    }

    // 删除房屋类型
    @DeleteMapping("/type/{typeId}")
    @ResponseBody
    @SystemLog(name = "删除房屋类型")
    public R deleteHouseType(@PathVariable Integer typeId) {
        return houseService.deleteHouseType(typeId);
    }

    // 添加房屋状态
    @PostMapping("/status")
    @ResponseBody
    @SystemLog(name = "添加房屋状态")
    public R addHouseStatus(String statusName) {
        return houseService.addHouseStatus(statusName);
    }

    // 删除房屋状态
    @DeleteMapping("/status/{statusId}")
    @ResponseBody
    @SystemLog(name = "删除房屋状态")
    public R deleteHouseStatus(@PathVariable Integer statusId) {
        return houseService.deleteHouseStatus(statusId);
    }

}
